import axioser from './modules'

/**
 * 登录接口
 * @param {{ username: string, password: string }}
 * @returns
 */
export const login = async ({ username, password }) => {
  return axioser.post('/auth/login', { username, password })
}

/**
 * 注册接口
 * @param {{ username: string, password: string, email?: string }}
 * @returns
 */
export const register = async ({ username, password, email = '' }) => {
  return axioser.post('/auth/login', { username, password, email })
}

/**
 * 角色CURD
 */
export const getRoles = async ({ page = 1, limit = 20, ...params }) => {
  return axioser.get('/role', { page, limit, ...params })
}
export const getRole = async (id) => {
  return axioser.get(`/role/${id}`)
}
export const addRole = async ({ code, description = '', permissions = [] }) => {
  return axioser.post('/role', { code, description, permissions })
}
export const updRole = async (id, data) => {
  return axioser.put(`/role/${id}`, data)
}
export const delRole = async (id) => {
  return axioser.delete(`/role/${id}`)
}
export const delBatchRole = async (ids) => {
  return axioser.delete(`/role/batch/${ids}`)
}

/**
 * 权限CURD
 */
export const getPermissions = async ({ page = 1, limit = 20, ...params }) => {
  return axioser.get('/permission', { page, limit, ...params })
}
export const getPermission = async (id) => {
  return axioser.get(`/permission/${id}`)
}
export const addPermission = async ({ code, description = '' }) => {
  return axioser.post('/permission', { code, description })
}
export const updPermission = async (id, data) => {
  return axioser.put(`/permission/${id}`, data)
}
export const delPermission = async (id) => {
  return axioser.delete(`/permission/${id}`)
}
export const delBatchPermission = async (ids) => {
  return axioser.delete(`/permission/batch/${ids}`)
}

/**
 * 用户CURD
 */
export const getUsers = async ({ page = 1, limit = 20, ...params }) => {
  return axioser.get('/user', { page, limit, ...params })
}
export const getUser = async (id) => {
  return axioser.get(`/user/${id}`)
}
/**
 *
 * @param {{ username: string, password: string, type?: number, sex?: number, mobile?: string, email?: string, avatar?: string, nickname?: string, real_name?: string, id_card?: string, description?: string, label?: string, roles?: Array }} data
 * @returns
 */
export const addUser = async (data) => {
  return axioser.post('/user', data)
}
/**
 * @param {string} id
 * @param {{{ password, type, sex,mobile, email, avatar, nickname, real_name, id_card, description, label, roles }}} data
 * @returns
 */
export const updUser = async (id, data) => {
  return axioser.put(`/user/${id}`, data)
}
export const delUser = async (id) => {
  return axioser.delete(`/user/${id}`)
}
export const delBatchUser = async (ids) => {
  return axioser.delete(`/user/batch/${ids}`)
}
export const getProfile = async () => {
  return axioser.get(`/user/profile/info`)
}
